package com.bwie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.bwie.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.mapper.ActivityMapper;
import com.bwie.domain.Activity;
import com.bwie.service.ActivityService;
import org.springframework.transaction.annotation.Transactional;
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class ActivityServiceImpl extends ServiceImpl<ActivityMapper, Activity> implements ActivityService{

    @Autowired
    private ActivityMapper activityMapper;
    @Override
    public R getActivityList() {
        List<Activity> activities = activityMapper.selectList(null);
        return R.OK(activities);

    }

    @Override
    public R insertActivity(Activity activity) {
        activityMapper.insert(activity);
        return R.OK();
    }

    @Override
    public R updateActivity(Activity activity) {
        LambdaQueryWrapper<Activity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Activity::getActivityId,activity.getActivityId());
        activityMapper.updateById(activity);
        return R.OK();
    }

    @Override
    public R deleteActivity(Integer id) {
        LambdaQueryWrapper<Activity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Activity::getActivityId,id);
        Activity activity = activityMapper.selectOne(wrapper);
        activityMapper.deleteById(activity);
        return R.OK();
    }
}
